<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="/static/js/head.js"></script>
<link rel="stylesheet" type="text/css" href="/static/css/smallItemList.css" />
<style>
.formLeft{width:auto;}
</style>
</head> 
<body id="layout" class="easyui-layout">
	<div data-options="region:'center',border:false">
		<table id="infoDrid"></table>
	</div>
	<input type="hidden" id="contractOrderId">
	<!-- dataGrid工具栏 -->
	<div id="toolbar">
		<a id="uploadBTN" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-ccOut',plain:true" >上传文件</a>
		<a id="checkFile" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-accolist',plain:true" >查看附件</a>
		<a id="createContractOrder" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-ccAdd',plain:true" >添加小项</a>
		<a id="update" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-ccEdit',plain:true" >修改小项</a>
		<!--<a id="search" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-ccSearch',plain:true" >查询</a> -->
		<a id="finish" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-lock',plain:true" >结束小项</a>
		<a id="delete" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true" >删除小项</a>
		<a id="paid" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-ok',plain:true" >支付尾款</a>
	</div>
	<!-- 添加 -->
	<div id="addDialog">
		<form id="addForm">
			<table class="tableForm">
				<tr>
					<td class="formLeft">名称:</td>
					<td>
						<input class="easyui-validatebox" data-options="required:true" name="addName" id="addName">
					</td>
				</tr>
				<tr>
					<td class="formLeft">合作单位:</td>
					<td>
						<input class="easyui-validatebox" data-options="required:true" name="addCooperator" id="addCooperator">
					</td>
				</tr>
				<tr>
					<td class="formLeft">开始日期:</td>
					<td>
						<input class="easyui-datebox"  data-options="required:true" name="addStartDate" id="addStartDate">
					</td>
				</tr>
				<tr>
					<td class="formLeft">验收日期:</td>
					<td>
						<input class="easyui-datebox" name="addCheckAndAcceptDate" id="addCheckAndAcceptDate">
					</td>
				</tr>
				<tr>
					<td class="formLeft">审定总金额:</td>
					<td>
						<input class="easyui-numberbox" data-options="min:0" name="addAmount" id="addAmount">
					</td>
				</tr>
				<tr>
					<td class="formLeft">审定乙方施工费:</td>
					<td>
						<input class="easyui-numberbox" data-options="min:0" name="addSecondPartyConstructionCost" id="addSecondPartyConstructionCost" precision="2">
					</td>
				</tr>
				<tr>
					<td class="formLeft">审定甲方提供材料费:</td>
					<td>
						<input class="easyui-numberbox" data-options="min:0" name="addFirstPartyMaterialCost" id="addFirstPartyMaterialCost" precision="2">
					</td>
				</tr>
				<tr>
					<td class="formLeft">审定乙方提供材料费:</td>
					<td>
						<input class="easyui-numberbox" data-options="min:0" name="addSecondPartyMaterialCost" id="addSecondPartyMaterialCost" precision="2">
					</td>
				</tr>
				<tr>
					<td class="formLeft">乙方安全生产费:</td>
					<td>
						<input class="easyui-numberbox" data-options="min:0" name="addSecondPartySafeProductionCost" id="addSecondPartySafeProductionCost" precision="2">
					</td>
				</tr>
				<tr>
					<td class="formLeft">规费:</td>
					<td>
						<input class="easyui-numberbox" data-options="min:0" name="addStipulatedFee" id="addStipulatedFee" precision="2">
					</td>
				</tr>
				<tr>
					<td class="formLeft">施工队审计费:</td>
					<td>
						<input class="easyui-numberbox" data-options="min:0" name="addSecondPartyAuditFee" id="addSecondPartyAuditFee" precision="2">
					</td>
				</tr>
				<tr>
					<td class="formLeft">施工队扣款:</td>
					<td>
						<input class="easyui-numberbox" data-options="min:0" name="addSecondPartyDeductedAmount" id="addSecondPartyDeductedAmount" precision="2">
					</td>
				</tr>
				<!-- <tr>
					<td class="formLeft">应扣税款:</td>
					<td>
						<input class="easyui-numberbox" data-options="min:0" name="addTaxAmount" id="addTaxAmount">
					</td>
				</tr> -->
				<tr>
					<td class="formLeft">管理费:</td>
					<td>
						<input class="easyui-numberbox" data-options="min:0" name="addManagementFee" id="addManagementFee" precision="2">
					</td>
				</tr>
			</table>
		</form>
	</div>
	<div id="updateDialog">
		<form id="updateForm">
			<table class="tableForm">
				<tr>
					<td class="formLeft">小项名称:</td>
					<td>
						<input class="easyui-validatebox" data-options="required:true" name="name" id="name">
						<input id="smallId" value="0" type="hidden">
					</td>
				</tr>
				<tr>
					<td class="formLeft">合作单位:</td>
					<td>
						<input class="easyui-validatebox" data-options="required:true" name="cooperator" id="cooperator">
					</td>
				</tr>
				<tr>
					<td class="formLeft">开始日期:</td>
					<td id="updateRoleTD">
						<input class="easyui-datebox"  data-options="required:true" name="startDate" id="startDate">
					</td>
				</tr>
				<tr>
					<td class="formLeft">验收日期:</td>
					<td>
						<input class="easyui-datebox" name="checkAndAcceptDate" id="checkAndAcceptDate">
					</td>
				</tr>
				<tr>
					<td class="formLeft">审定总金额:</td>
					<td>
						<input class="easyui-numberbox" data-options="min:0" name="amount" id="amount" precision="2">
					</td>
				</tr>
				<tr>
					<td class="formLeft">审定乙方施工费:</td>
					<td>
						<input class="easyui-numberbox" data-options="min:0" name="secondPartyConstructionCost" id="secondPartyConstructionCost" precision="2">
					</td>
				</tr>
				<tr>
					<td class="formLeft">审定甲方提供材料费:</td>
					<td>
						<input class="easyui-numberbox" data-options="min:0" name="firstPartyMaterialCost" id="firstPartyMaterialCost" precision="2">
					</td>
				</tr>
				<tr>
					<td class="formLeft">审定乙方提供材料费:</td>
					<td>
						<input class="easyui-numberbox" data-options="min:0" name="secondPartyMaterialCost" id="secondPartyMaterialCost" precision="2">
					</td>
				</tr>
				<tr>
					<td class="formLeft">乙方安全生产费:</td>
					<td>
						<input class="easyui-numberbox" data-options="min:0" name="secondPartySafeProductionCost" id="secondPartySafeProductionCost" precision="2">
					</td>
				</tr>
				<tr>
					<td class="formLeft">规费:</td>
					<td>
						<input class="easyui-numberbox" data-options="min:0" name="stipulatedFee" id="stipulatedFee" precision="2">
					</td>
				</tr>
				<tr>
					<td class="formLeft">施工队审计费:</td>
					<td>
						<input class="easyui-numberbox" data-options="min:0" name="secondPartyAuditFee" id="secondPartyAuditFee" precision="2">
					</td>
				</tr>
				<tr>
					<td class="formLeft">施工队扣款:</td>
					<td>
						<input class="easyui-numberbox" data-options="min:0" name="secondPartyDeductedAmount" id="secondPartyDeductedAmount" precision="2">
					</td>
				</tr>
				<!-- <tr>
					<td class="formLeft">应扣税款:</td>
					<td>
						<input class="easyui-numberbox" data-options="min:0" name="taxAmount" id="taxAmount">
					</td>
				</tr> -->
				<tr>
					<td class="formLeft">管理费:</td>
					<td>
						<input class="easyui-numberbox" data-options="min:0" name="managementFee" id="managementFee" precision="2">
					</td>
				</tr>
			</table>
		</form>
	</div>
	<!-- 上传 -->
	<div id="uploadDialog">
		<form id="uploadForm" enctype="multipart/form-data" method="post" accept-charset="UTF-8" >
			<table class="tableForm">
				<tr>
					<td><label>上传类型</label></td>
					<td>
						<label><input type="radio" name="certType" checked="checked" value="1">验收证书</label>
			            <label><input type="radio" name="certType" value="2">审核报告</label>
			            <label><input type="radio" name="certType" value="3">扣款凭证</label>
			            <label><input type="radio" name="certType" value="4">实际付款数凭证</label>
			            <label><input type="radio" name="certType" value="5">尾款支付</label>
					</td>
				</tr>
				<tr id="inputCB1" >
					<td><label>选择文件</label></td>
					<td>
						<input id="miData" type="text">
						<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-upload',plain:true"
							onClick="document.getElementById('file').click()"></a>
						<input type="file" style="width:300px" id="file" name="file" class="filePrew"
						 onchange="change_photo();" multiple="multiple">
					</td>
				</tr>
				<tr id="inputCB4" >
					<td ><label>图片预览</label></td>
					<td>
						<div id="Imgdiv">
						</div>
					</td>
				</tr>
			</table>
		</form>
	</div>
</body>
</html>

<script>
	$(function(){
		$.ajaxSetup({crossDomain: true, xhrFields: {withCredentials: true}});
		$("#contractOrderId").val(sessionStorage.getItem('orderId'));
		//页面初始化
		layoutLoad();
		//数据表格加载
		gridLoad(1,15);	
		//点击事件
		clickFunction();
	});
	//页面初始化
	function layoutLoad(){
//		$('#layout').layout('collapse','east');
		//信息添加dialog
		$('#addDialog').dialog({
			title: '添加小项',
		    width: 400,
		    height:550,
		    closed: true,    
		    modal: true,
		    buttons:[{
				text:'确定',
				iconCls:'icon-ok',
				handler:function(){
					addInfo();//添加信息
                }
			},{
				text:'取消',
				iconCls:'icon-cancel',
				handler:function(){
					$('#addDialog').dialog('close');
				}
			}], 
		});
		$('#updateDialog').dialog({
			title: '更新财务信息',
		    width: 400,
		    height:550,
		    closed: true,
		    modal: true,
		    buttons:[{
				text:'确定',
				iconCls:'icon-ok',
				handler:function(){
					updatedInfo();//添加信息
                }
			},{
				text:'取消',
				iconCls:'icon-cancel',
				handler:function(){
					$('#updateDialog').dialog('close');
				}
			}], 
		});
		//上传dialog
		$('#uploadForm').dialog({
			title: '上传',
		    width: 500,
		    height:500,
		    closed: true,    
		    modal: true,
		    buttons:[{
				text:'确定',
				iconCls:'icon-ok',
				handler:function(){
					uploadFiles()
                }
			},{
				text:'取消',
				iconCls:'icon-cancel',
				handler:function(){
					$('#uploadForm').dialog('close');
				}
			}], 
		});
	}
	//数据表格加载
	function gridLoad(pageNumber,pageSize) {
		$.ajax({
			url : getHost() + '/small_item/list/pageable/adapter/order_by_create_time_desc',
			type : "GET",
			data : {
				"pageNumber": pageNumber,
			    "pageSize": pageSize,
			    "contractOrderId" : $("#contractOrderId").val()
			},
			async : false,
			dataType : "json",
			contentType: 'application/json;charset=UTF-8',
			success : function(data) {
				if (data.code==200&&typeof(data.data) == "object") {
					var width = $('#infoDrid').parent().width();
					var height = $('#infoDrid').parent().height();
					$('#infoDrid').datagrid({
						toolbar : "#toolbar",
						data: data.data.page.rows,
						width : width,
						height : height,
						async : false,
						fit : true,
						border : false,
						singleSelect : true,
						fitColumns : true,
						striped : true,
						pagination : true,
						scrollbarSize:0 ,
						columns : [ [
							{field:'name',title:'小项名称' ,align:'center'},
							{field:'cooperator',title:'合作单位' ,align:'center'},
							{field:'startDate',title:'开始日期',align:'center'},
							{field:'endDate',title:'结束日期',align:'center'},
							{field:'status',title:'状态',align:'center',
								formatter: function(value,row,index){
									if(value=="2"){
										return "已结束";
									}else if(value=="1"){
										return "进行中";
									}else{
										return "";
									}
								}
							},
							{field:'checkAndAcceptDate',title:'验收日期',align:'center'},
							{field:'amount',title:'审定总金额',align:'center' },
							{field:'secondPartyConstructionCost',title:'审定乙方施工费',align:'center'},
							{field:'firstPartyMaterialCost',title:'审定甲供材料费',align:'center'},
							{field:'secondPartyMaterialCost',title:'审定乙供材料费',align:'center'},
							{field:'secondPartySafeProductionCost',title:'乙方安全生产费用',align:'center'},
							{field:'stipulatedFee',title:'规费',align:'center'},
							{field:'invoiceAmount',title:'小项开票金额',align:'center'},
							{field:'amountCashed',title:'小项回款额',align:'center'},
							{field:'secondPartyAuditFee',title:'施工队审计费',align:'center'},
							{field:'secondPartyDeductedAmount',title:'施工队扣款',align:'center'},
							{field:'taxAmount',title:'应扣税款',align:'center'},
							{field:'managementFee',title:'管理费',align:'center'},
							{field:'accountPayable',title:'应付款',align:'center'},
							{field:'actualPayment',title:'实际付款',align:'center'},
							{field:'balance',title:'应付尾款',align:'center'},
							{field:'totalPaid',title:'尾款支付状态',align:'center',
								formatter: function(value,row,index){
									if(value){
										return "已支付";
									}else if(!value){
										return "未支付";
									}else{
										return "";
									}
								}
							},
						] ],
					});
					var p = $('#infoDrid').datagrid('getPager');
			        $(p).pagination({
			        	total : data.data.page.total,
			            pageSize: pageSize,
			            pageList: [15, 30, 50],
			            pageNumber : pageNumber,
			            beforePageText: '第',
			            afterPageText: '页    共 {pages} 页',
			            displayMsg: '当前显示 {from}-{to} 条记录,共 {total} 条记录',
			            showRefresh : false,
			            onSelectPage:function(pageNumber, pageSize){
			        		gridLoad(pageNumber,pageSize);
			        	}
			        });
				}else{
					$.messager.alert("提示",data.message);
				}
			}
		});
	}
	//点击事件
	function clickFunction() {
		$('#search').click(function() {
			$('#layout').layout('expand', 'east');
		});
		//点击查询
		$('#searchbtn').click(function() {
			gridLoad(1,15);
		});
		$('#resetbtn').click(function() {
			$('#searchForm')[0].reset();
			$("#loginnameSearch").val('');
			$("#signdate").val('');
			$('#stattimeSearch').datetimebox('setValue', '');
			$('#endtimeSearch').datetimebox('setValue', '');
			gridLoad(1,15);
		});
		
		//订单详情
		$('#update').click(function() {
			var row = $('#infoDrid').datagrid('getSelected');
			if(row==null){
				$.messager.alert("提示","请选中一行!");
				return;
			}
			$('#updateForm')[0].reset();
			$("#smallId").val(row.id);
			$('#updateForm').form('load',row);
			$('#updateDialog').dialog('open');
		});
		//查看合同订单列表 
		$('#orderList').click(function() {
			parent.addTab('订单详情', "url")
		});
		$('#createContractOrder').click(function(){
			$('#addForm')[0].reset();
			$('#addDialog').dialog('open');
		});
		//删除 
		$('#delete').click(function() {
			var row = $('#infoDrid').datagrid('getSelected');
			if(row==null){
				$.messager.alert("提示","请选中一行!");
				return;
			}
			$.messager.confirm('提示','确定要删除该小项吗?<br/>'+row.name,function(r){
			    if (r){
			    	$.ajax({
						url:getHost() + '/small_item/' + row.id,
						type:'DELETE',
						error:function(){
							$.messager.alert("提示","数据操作存在异常!");
						},
						contentType: 'application/json;charset=UTF-8',
						success:function(data){
							if(data.code==200){
								$.messager.alert("提示","删除成功");
								gridLoad(1,15);
							}else{
								$.messager.alert("提示",data.message);
							}
						}
					});
			    }
			});
		});
		//结束
		$('#finish').click(function() {
			var row = $('#infoDrid').datagrid('getSelected');
			if(row==null){
				$.messager.alert("提示","请选中一行!");
				return;
			}
			$.messager.confirm('提示','确定要结束该小项吗?',function(r){
			    if (r){
			    	$.ajax({
						url:getHost() + '/small_item/end?smallItemId=' + row.id,
						type:'GET',
						error:function(){
							$.messager.alert("提示","数据操作存在异常!");
						},
						contentType: 'application/json;charset=UTF-8',
						success:function(data, textStatus, request){
							if(data.code==200){
								$.messager.alert("提示","操作成功");
								gridLoad(1,15);
							}else{
								$.messager.alert("提示",data.message);
							}
						}
					});
			    }
			});
		});
		//确认支付尾款
		$('#paid').click(function() {
			var row = $('#infoDrid').datagrid('getSelected');
			if(row==null){
				$.messager.alert("提示","请选中一行!");
				return;
			}
			if(!row.totalPaid){
			}else{
				$.messager.alert("提示","尾款已经支付。");
				return;
			}
			$.messager.confirm('提示','确定要支付尾款吗?',function(r){
			    if (r){
			    	$.ajax({
						url:getHost() + '/small_item/total_paid',
						type:'PUT',
						data : JSON.stringify({
							"id": row.id,
						    "status": true,
						}),
						error:function(){
							$.messager.alert("提示","数据操作存在异常!");
						},
						dataType : "json",
						contentType: 'application/json;charset=UTF-8',
						success:function(data, textStatus, request){
							if(data.code==200){
								$.messager.alert("提示","操作成功");
								gridLoad(1,15);
							}else{
								$.messager.alert("提示",data.message);
							}
						}
					});
			    }
			});
		});
		//上传 
		$('#uploadBTN').click(function() {
			var row = $('#infoDrid').datagrid('getSelected');
			if(row==null){
				$.messager.alert("提示","请选中一行!");
				return;
			}
			$('#uploadForm')[0].reset();
			$('#uploadForm').dialog('open');
		});
		//查看附件
		$('#checkFile').click(function() {
			var row = $('#infoDrid').datagrid('getSelected');
			if(row==null){
				$.messager.alert("提示","请选中一行!");
				return;
			}
			sessionStorage.setItem('fileType','3');
			sessionStorage.setItem('row',JSON.stringify(row));
			parent.addTab('附件展示',  "/accessories.html");
		});
	}
	//添加信息
	function addInfo(){
		if($("#addForm").form('validate')){
			$.ajax({
				url:getHost() + '/small_item',
				type:'POST',
				data:JSON.stringify({
					contractOrderId : $("#contractOrderId").val(),
					name : $("#addName").val(),
					cooperator : $("#addCooperator").val(),
					startDate : $("#addStartDate").val(),
					checkAndAcceptDate : $("#addCheckAndAcceptDate").val(),
					amount : $("#addAmount").val(),
					secondPartyConstructionCost : $("#addSecondPartyConstructionCost").val(),
					firstPartyMaterialCost : $("#addFirstPartyMaterialCost").val(),
					secondPartyMaterialCost : $("#addSecondPartyMaterialCost").val(),
					secondPartySafeProductionCost : $("#addSecondPartySafeProductionCost").val(),
					stipulatedFee : $("#addStipulatedFee").val(),
					secondPartyAuditFee : $("#addSecondPartyAuditFee").val(),
					secondPartyDeductedAmount : $("#addSecondPartyDeductedAmount").val(),
					/* taxAmount : $("#addTaxAmount").val(), */
					managementFee : $("#addManagementFee").val(),
				}),
				contentType: 'application/json;charset=UTF-8',
				beforeSend: function(xhr) {
	                xhr.withCredentials = true;
	            },
	            crossDomain:true,
				error:function(){
					$.messager.alert("提示","数据操作存在异常!");
					$('#addDialog').dialog('close');
				},
				success:function(data){
					if(data.code==200&&typeof(data.data) == "object"&&typeof(data.data.item) == "object"&&data.data.item.id>0){
						$.messager.alert("提示","创建成功");
						$('#addForm').form('clear');
						$('#addDialog').dialog('close');
						$('#infoDrid').datagrid('load');
						gridLoad(1,15);
					}else{
						$.messager.alert("提示",data.message);
					}
				}
			});
		}
	}
	//更新小项信息
	function updatedInfo(){
		if($("#updateForm").form('validate')){
			var checkAndAcceptAttachmentIdList = new Array(),auditReportAttachmentIdList = new Array()
			,secondPartyDeductionAttachmentIdList = new Array(),actualPaymentAttachmentIdList = new Array();
			var row = $('#infoDrid').datagrid('getSelected');
			actualPaymentAttachmentIdList = JSON.parse(getID(JSON.stringify(row.actualPaymentAttachmentList)));
			auditReportAttachmentIdList = JSON.parse(getID(JSON.stringify(row.auditReportAttachmentList)));
			secondPartyDeductionAttachmentIdList = JSON.parse(getID(JSON.stringify(row.secondPartyDeductionAttachmentList)));
			checkAndAcceptAttachmentIdList = JSON.parse(getID(JSON.stringify(row.checkAndAcceptAttachmentList)));
			$.ajax({
				url:getHost() + '/small_item',
				type:'PUT',
				data:JSON.stringify({
					"name": $("#name").val(),
				    "cooperator": $("#cooperator").val(),
				    "startDate": $("#startDate").val(),
				    "checkAndAcceptDate" : $("#checkAndAcceptDate").val(),
					"amount" : $("#amount").val(),
					"secondPartyConstructionCost" : $("#secondPartyConstructionCost").val(),
					"firstPartyMaterialCost" : $("#firstPartyMaterialCost").val(),
					"secondPartyMaterialCost" : $("#secondPartyMaterialCost").val(),
					"secondPartySafeProductionCost" : $("#secondPartySafeProductionCost").val(),
					"stipulatedFee" : $("#stipulatedFee").val(),
					"amountCashed" : $("#amountCashed").val(),
					"secondPartyAuditFee" : $("#secondPartyAuditFee").val(),
					"secondPartyDeductedAmount" : $("#secondPartyDeductedAmount").val(),
					/* "taxAmount" : $("#taxAmount").val(), */
					"managementFee" : $("#managementFee").val(),
				    "id": $("#smallId").val(),
				    checkAndAcceptAttachmentIdList : checkAndAcceptAttachmentIdList,
					auditReportAttachmentIdList : auditReportAttachmentIdList,
					secondPartyDeductionAttachmentIdList : secondPartyDeductionAttachmentIdList,
					actualPaymentAttachmentIdList : actualPaymentAttachmentIdList,
				}),
				contentType: 'application/json;charset=UTF-8',
				error:function(){
					$.messager.alert("提示","数据操作存在异常!");
					$('#updateDialog').dialog('close');
				},
				beforeSend: function(xhr) {
	                xhr.withCredentials = true;
	            },
	            crossDomain:true,
				success:function(data){
					if(data.code==200&&typeof(data.data) == "object"&&typeof(data.data.item) == "object"&&data.data.item.id>0){
						$.messager.alert("提示","修改成功");
						$('#updateForm').form('clear');
						$('#updateDialog').dialog('close');
						//$('#infoDrid').datagrid('load');
						gridLoad(1,15);
					}else{
						$.messager.alert("提示",data.message);
					}
				}
			});
		}
	}
	//上传
	function uploadFiles(){
 	    var count = 0;
	    var ids = "";
    	var files = document.getElementById("file").files;
    	var fl = files.length;
		for(var i=0; i< fl; i++){
			var fileObj = document.getElementById("file").files[i];
			var formFile = new FormData();
            formFile.append("file", fileObj); //加入文件对象
			$.ajax({
				url:getHost() + '/file',
				type : 'post',
                data: formFile,
				error : function(data) {
					$.messager.alert('提示', "第"+i+"张"+'上传失败！');
				},
				contentType : false,
				processData : false,
				async : false,
				success : function(data) {
					if(data.code=="200"&&data.data.item.id>0){
						ids += data.data.item.id + ",";
						count+=1;
					}else{
						$.messager.alert("提示","第"+i+"张"+data.message);
					}
				}
			});
		}
		if(count==fl){
			var row = $('#infoDrid').datagrid('getSelected');
			var checkAndAcceptAttachmentIdList = new Array(),auditReportAttachmentIdList = new Array()
			,secondPartyDeductionAttachmentIdList = new Array(),actualPaymentAttachmentIdList = new Array()
			,balancePaymentAttachmentIdList = new Array();
			if($("input[name='certType']:checked").val()==1){
				checkAndAcceptAttachmentIdList = JSON.parse("["+ids.substring(0,ids.length-1)+"]");
				auditReportAttachmentIdList = JSON.parse(getID(JSON.stringify(row.auditReportAttachmentList)));
				secondPartyDeductionAttachmentIdList = JSON.parse(getID(JSON.stringify(row.secondPartyDeductionAttachmentList)));
				actualPaymentAttachmentIdList = JSON.parse(getID(JSON.stringify(row.actualPaymentAttachmentList)));
				balancePaymentAttachmentIdList = JSON.parse(getID(JSON.stringify(row.balancePaymentAttachmentIdList)));
			}else if($("input[name='certType']:checked").val()==2){
				auditReportAttachmentIdList = JSON.parse("["+ids.substring(0,ids.length-1)+"]");
				checkAndAcceptAttachmentIdList = JSON.parse(getID(JSON.stringify(row.checkAndAcceptAttachmentList)));
				secondPartyDeductionAttachmentIdList = JSON.parse(getID(JSON.stringify(row.secondPartyDeductionAttachmentList)));
				actualPaymentAttachmentIdList = JSON.parse(getID(JSON.stringify(row.actualPaymentAttachmentList)));
				balancePaymentAttachmentIdList = JSON.parse(getID(JSON.stringify(row.balancePaymentAttachmentIdList)));
			}else if($("input[name='certType']:checked").val()==3){
				secondPartyDeductionAttachmentIdList = JSON.parse("["+ids.substring(0,ids.length-1)+"]");
				auditReportAttachmentIdList = JSON.parse(getID(JSON.stringify(row.auditReportAttachmentList)));
				checkAndAcceptAttachmentIdList = JSON.parse(getID(JSON.stringify(row.checkAndAcceptAttachmentList)));
				actualPaymentAttachmentIdList = JSON.parse(getID(JSON.stringify(row.actualPaymentAttachmentList)));
				balancePaymentAttachmentIdList = JSON.parse(getID(JSON.stringify(row.balancePaymentAttachmentIdList)));
			}else if($("input[name='certType']:checked").val()==4){
				actualPaymentAttachmentIdList = JSON.parse("["+ids.substring(0,ids.length-1)+"]");
				auditReportAttachmentIdList = JSON.parse(getID(JSON.stringify(row.auditReportAttachmentList)));
				secondPartyDeductionAttachmentIdList = JSON.parse(getID(JSON.stringify(row.secondPartyDeductionAttachmentList)));
				checkAndAcceptAttachmentIdList = JSON.parse(getID(JSON.stringify(row.checkAndAcceptAttachmentList)));
				balancePaymentAttachmentIdList = JSON.parse(getID(JSON.stringify(row.balancePaymentAttachmentIdList)));
			}else if($("input[name='certType']:checked").val()==5){
				balancePaymentAttachmentIdList = JSON.parse("["+ids.substring(0,ids.length-1)+"]");
				actualPaymentAttachmentIdList = JSON.parse(getID(JSON.stringify(row.actualPaymentAttachmentList)));
				auditReportAttachmentIdList = JSON.parse(getID(JSON.stringify(row.auditReportAttachmentList)));
				secondPartyDeductionAttachmentIdList = JSON.parse(getID(JSON.stringify(row.secondPartyDeductionAttachmentList)));
				checkAndAcceptAttachmentIdList = JSON.parse(getID(JSON.stringify(row.checkAndAcceptAttachmentList)));
			}
			$.ajax({
				url:getHost() + '/small_item',
				type:'PUT',
				data:JSON.stringify({
					name : row.name,
				    cooperator : row.cooperator,
				    startDate : row.startDate,
				    checkAndAcceptDate : row.checkAndAcceptDate,
					amount : row.amount,
					secondPartyConstructionCost : row.secondPartyConstructionCost,
					firstPartyMaterialCost : row.firstPartyMaterialCost,
					secondPartyMaterialCost : row.secondPartyMaterialCost,
					secondPartySafeProductionCost : row.secondPartySafeProductionCost,
					stipulatedFee : row.stipulatedFee,
					amountCashed : row.amountCashed,
					secondPartyAuditFee : row.secondPartyAuditFee,
					secondPartyDeductedAmount : row.secondPartyDeductedAmount,
					/* taxAmount : row.taxAmount, */
					managementFee : row.managementFee,
					id : row.id,
					checkAndAcceptAttachmentIdList : checkAndAcceptAttachmentIdList,
					auditReportAttachmentIdList : auditReportAttachmentIdList,
					secondPartyDeductionAttachmentIdList : secondPartyDeductionAttachmentIdList,
					actualPaymentAttachmentIdList : actualPaymentAttachmentIdList,
					balancePaymentAttachmentIdList : balancePaymentAttachmentIdList,
				}),
				dataType : "json",
				contentType: 'application/json;charset=UTF-8',
				error : function(XMLHttpRequest, textStatus, errorThrown){
					$.messager.alert("提示","数据操作存在异常!");
				},
				beforeSend: function(xhr) {
	                xhr.withCredentials = true;
	            },
	            crossDomain:true,
				success:function(data){
					if(data.code=="200"&&data.data.item.id>0){
						$.messager.alert("提示","上传成功");
						$('#uploadForm').form('clear');
						$("#Imgdiv").html("");
						gridLoad(1,15);
						$('#uploadForm').dialog('close');
					}else{
						$.messager.alert("提示",data.message);
					}
				}
			});
		}
	}
	function change_photo(){
		$("#Imgdiv").html("");
		var files = document.getElementById("file").files;
		var names = "";
		for(var i=0; i< files.length; i++){
			names += files[i].name+",";
		}
		$("#miData").val(names.substring(0,names.length));
	    PreviewImage($("input[id='file']")[0]);
	}
	function PreviewImage(fileObj){
	    var allowExtention=".jpg,.bmp,.gif,.png,.jpeg";//允许上传文件的后缀名document.getElementById("hfAllowPicSuffix").value;  
	    var browserVersion= window.navigator.userAgent.toUpperCase();
	    //循环判断后缀名
	    for(i=0;i<fileObj.files.length;i++){
	    	var extention=fileObj.files[i].name.substring(fileObj.files[i].name.lastIndexOf("."),fileObj.files[i].name.length).toLowerCase();
	    	if(allowExtention.indexOf(extention)<0){
	    		$.messager.alert("仅支持"+allowExtention+"为后缀名的文件!");  
	   	        fileObj.value="";//清空选中文件  
	   	        if(browserVersion.indexOf("MSIE")>-1){
	   	            fileObj.select();  
	   	            document.selection.clear();  
	   	        }                  
	   	        fileObj.outerHTML=fileObj.outerHTML;
	   	        return false;
	    	}
	    }
	    
	    $.each(fileObj.files,function(key,value){
	        //每次都只会遍历一个图片数据
	        var div = document.createElement("div");
	        var img = document.createElement("img");
	        div.className = "pic";
	        img.width="200";
	        img.height="200";

	        var fr = new FileReader();
	        fr.onload = function(){
	        	if(this.result.substring(5,this.result.indexOf("/"))=="image"){
		            img.src=this.result;
	        	}else{
	        		img.src="/static/images/compress.jpg";
	        	}
	            div.appendChild(img);
	            document.getElementById("Imgdiv").appendChild(div);
	        }
	        fr.readAsDataURL(value);
	    })
	}
	function getID(con){
		con = JSON.parse(con);
		var str = "";
		for(i=0;i<con.length;i++){
			str += con[i].id + ",";
		}
		return "["+str.substring(0,str.length-1)+"]";
	}
</script>